const jwt = require('jsonwebtoken')

module.exports = function(req,res,next){
    let token = req.get('token')
    if(!token){
        res.json({
            code:'2004',
            msg: 'token缺失',
            data: null
        })
    }
    jwt.verify(token,'atguigu',(err, data)=>{
        if(err){
            return res.json({
                code:'2003',
                msg:' token解析错误',
                data:null
            })
        }
        next()
    })
}